package com.xiaren.ui.edit;

import java.io.FileOutputStream;
import java.io.ObjectOutputStream;

import com.xiaren.common.IConstant;
import com.xiaren.common.ObjectConstant;

/**
 * 以序列化的方式读写文件
 *
 * @author xiaren
 * @主页 http://www.leaf123.cn/
 * @邮箱 xia5523@qq.com
 */
public class SeriSaveRead {

	/**
	 * 新的保存文本的方法
	 *
	 * @param edit
	 */
	public static void saveFile(FileEdit edit) {
		if (!edit.isSave) {// 如果没有保存，就保存一下
			try {
				FileOutputStream fos = new FileOutputStream(IConstant.PATH + edit.treeNote.treeNodeId + ".file");
				ObjectOutputStream oos = new ObjectOutputStream(fos);
				oos.writeObject(edit);
				oos.close();
				edit.isSave = true;
				int selectIndex = ObjectConstant.mainEdit
						.indexOfComponent(edit);
				String oldTitle = ObjectConstant.mainEdit
						.getTitleAt(selectIndex);

				String newTitle = oldTitle.substring(0, oldTitle.length() - 2);
				ObjectConstant.mainEdit.setTitleAt(selectIndex, newTitle);
			} catch (Exception e) {
				e.printStackTrace();
			}

		}
	}

}
